/**
 *2011/01/13
 * 作業者新城	：データベース　nak テーブル　shouhinへアクセス
 * 2011/01/13
 * 説明の読み込み追加
 *
 *
 * */

package shouhin;
import DBs.*;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;

//受けとった商品ID（itemID）とイコールの商品情報を商品テーブル(SYOUHIN)から抜き出す
public class SQLSearch extends HttpServlet implements Syori{

	public void doGet(HttpServletRequest req, HttpServletResponse res)
	throws ServletException, IOException{
		this.doPost(req, res);
	}

	public void doPost(HttpServletRequest req, HttpServletResponse res)
	throws IOException, ServletException{
		//コンテントのタイプとキャラセット
		res.setContentType("text/html; charset=UTF-8;");
		//実行文の格納
		String sql = "select * from syouhin";
		//DBExecのインスタンス
		DBExec dbe = new DBExec();
		dbe.selectTable(sql, new SQLSearch(), req, res);
	}

	public void syori(ResultSet rs, HttpServletRequest req, HttpServletResponse res){
		String itemID = req.getParameter("banText");
		int key =  Integer.parseInt(itemID);

		try{
			while(rs.next()){
				if(itemID.equals(rs.getString("SYOUHIN_ID"))){						//商品IDをキー
					req.setAttribute("bID", rs.getString("SYOUHIN_ID"));			//商品ＩＤの格納
					req.setAttribute("bNAME", rs.getString("SYOUHINMEI"));			//商品名
					req.setAttribute("bNEDAN", rs.getString("NEDAN"));				//値段
					req.setAttribute("bSETUMEI", rs.getString("SETUMEI"));			//説明
					req.setAttribute("bZAIKO", rs.getString("ZAIKO"));				//説明
					req.setAttribute("bIMG", rs.getString("img_url"));				//イメージＵＲＬ
					// req.setAttribute("bImgs", rs.getString("imgｓ_url"));     	//イメージＵＲＬスモール
					//
				}
			}

		}catch(SQLException e){
			e.printStackTrace();
		}

		RequestDispatcher dp = req
		.getRequestDispatcher("../src/jsp/shouhin/detailAndput.jsp");//タブ用分岐をJspの織り込む

		try {
			dp.forward(req, res);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ServletException e) {
			e.printStackTrace();
		}


	}
}
